<?php


namespace app\admin\controller;


use think\Controller;

class Comment extends Controller
{
    public function selectgoods(){
        $admin=session('admin');
        if(empty($admin)){
            $this->error('您未登录，不能进去后台管理','/admin/index/login');
        }
        $goods=db('goods')->field(['id','thumb','goods_name'])->paginate(6);
        $this->assign('goods',$goods);
        $this->assign('numleft',1);
        return view();
    }
    public function lst($id){
        $admin=session('admin');
        if(empty($admin)){
            $this->error('您未登录，不能进去后台管理','/admin/index/login');
        }
        $goods=db('goods')->where('id',$id)->find();
        if(empty($goods)){
            $this->error('该商品不存在','selectgoods');
        }else{
            $comment=db('comment')->alias('a')->field('a.*,b.name')->join('user b',"b.id=a.user_id and a.goods_id=$id and a.is_common=1")->paginate(6);
        }
        $this->assign([
            'goods_name'=>$goods['goods_name'],
            'comment'=>$comment
        ]);
        $this->assign('numleft',1);
        return view('list');
    }
}